package com.google.code.sip.ucenter.ws;

import java.util.Collection;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * WebService返回结果基类,定义所有返回码.
 * 
 * @author Liuye
 * 
 */
@XmlRootElement(name = "response")
@XmlAccessorType(XmlAccessType.NONE)
public class WSResponse<T> {
	@XmlElement(name = "status")
	private WSResponseStatus status;

	@XmlElement(name = "data")
	private WSResponseData<T> responseData = new WSResponseData<T>();

	public WSResponse() {// default success.
		this.setStatus(WSResponseStatus.SUCCESS);
	}

	public WSResponse(WSResponseStatus status) {
		this.setStatus(status);
	}

	public WSResponse(T data) {
		this.setStatus(WSResponseStatus.SUCCESS);
		this.addResult(data);
	}

	public WSResponse(List<T> data) {
		this.setStatus(WSResponseStatus.SUCCESS);
		this.addResult(data);
	}

	public WSResponseStatus getStatus() {
		return status;
	}

	public void setStatus(WSResponseStatus status) {
		this.status = status;
	}

	public List<T> getResult() {
		return responseData.getResult();
	}

	public T getFirstResult() {
		return responseData.getResult().get(0);
	}

	public WSResponseData<T> getResponseData() {
		return responseData;
	}

	public void setResponseData(WSResponseData<T> responseData) {
		this.responseData = responseData;
	}

	public void addResult(T result) {
		this.responseData.addResult(result);
	}

	public void addResult(Collection<T> result) {
		this.responseData.addResult(result);
	}
}
